//
//  ViewController.m
//  imageRevolve
//
//  Created by zhangyongbin on 3/10/15.
//  Copyright (c) 2015 Beijing YunJi Technology Company. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()
{
    UIImageView *_imageview;
    BOOL flag;
    
    NSInteger rr;
}

- (void)revolve;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    _imageview = [self ImageViewImageName:@"loading" frame:CGRectMake((self.view.frame.size.width - 23)/2, 100, 23, 23)];
    _imageview.animationImages = @[[UIImage imageNamed:@"arrow_down_0"], [UIImage imageNamed:@"arrow_down_1"], [UIImage imageNamed:@"arrow_down_2"], [UIImage imageNamed:@"arrow_down_3"]];
    _imageview.animationDuration = 1;
    [self.view addSubview:_imageview];
    
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(revolve) userInfo:nil repeats:YES];
    [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
    
    
    flag=YES;
    
    
#ifndef ViewController
    NSLog(@"a");
#else
    NSLog(@"b");
#endif
    
}


- (UIImageView *)ImageViewImageName:(NSString*)aImageName frame:(CGRect)aRect{
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:aRect];
    imageView.userInteractionEnabled = YES;
    UIImage *aImage = [UIImage imageNamed:(aImageName)];
    if ([aImage respondsToSelector:@selector(resizableImageWithCapInsets:)]) {
        imageView.image = [aImage resizableImageWithCapInsets:UIEdgeInsetsMake(aImage.size.height/2, aImage.size.width/2, aImage.size.height/2, aImage.size.width/2)];
    } else {
        imageView.image = [aImage stretchableImageWithLeftCapWidth:aImage.size.width/2 topCapHeight:aImage.size.height/2];
    }
    return imageView;
}


- (IBAction)click:(id)sender {
    if (flag) {
        
        
        //[_imageview startAnimating];
        flag=NO;
    } else {
        //[_imageview stopAnimating];
        flag=YES;
    }
}

- (void)revolve
{
    _imageview.transform = CGAffineTransformMakeRotation(M_PI/4*rr);
    rr++;
}

@end
